#!/usr/bin/env node
const path = require("path");
const fs = require("fs");
const { program } = require("commander");
const pkg = require("./package.json");
const { redmineClassify } = require("./bin/redmine/bugClassify");
const { mergePdf } = require("./bin/pdf/pdf");
const { promisify } = require("util");
const clear = require("clear");
const figlet = promisify(require("figlet"));
const chalk = require("chalk");
const { notion } = require("./bin/notion/index");
const { exportReport } = require("./bin/weeklyReport/report");
const { issuesUpload } = require("./bin/redmine/issuesUpload");
const { fileComment } = require("./bin/windows/fileComment");
const { netSet, addConfig, rmConfig, show } = require("./bin/netset/index");

(async () => {
  clear();
  const data = await figlet("H i K i t");
  console.log(chalk.green(data));
  let config = {};
  // 配置文件如果存在则读取
  // console.log(JSON.stringify(cells, null, 3));

  program.version(pkg.version, "-v, --version");
  program
    .command("redmine")
    .argument("<file>", "问题列表文件名")
    .option("-u,--upload", "问题上传至redmine")
    .action(async (file, option) => {
      if (option.upload) {
        console.log("option==", option);
        await issuesUpload(file);
      } else {
        await redmineClassify();
      }
    });
  program
    .command("mergePdf")
    .alias("pdf")
    .action((async) => {
      mergePdf();
    });
  program.command("notion").action(async () => {
    notion();
  });
  program
    .command("weeklyreport")
    .argument("<reportdate>", "报告日期YYYY-MM-DD")
    .alias("wr")
    .description(" date format YYYY-MM-DD")
    .action(async (reportdate) => {
      await exportReport(reportdate);
    });

  program
    .command("comment")
    .argument("<comment>", "备注名称")
    .description("windows 系统下给文件夹添加备注")
    .action(async (comment) => {
      await fileComment(comment);
    });

  program
    .command("netset")
    .description("修改网络设置")
    .argument("[name]", "需要删除的IP配置信息名称")
    .option("-add,--add", "添加IP配置")
    .option("-rm,--remove", "删除IP配置. netset -rm <name>")
    .option("-show,--show", "展示当前的IP配置信息。")
    .action(async (name, option) => {
      if (option.add) {
        await addConfig();
      } else if (option.remove) {
        rmConfig(name);
      } else if (option.show) {
        show();
      } else {
        await netSet();
      }
    });

  program.parse(process.argv);
})();
